import { http } from 'utils'

export function getAddressStruct() {
  return http
    .get('userAddress/createReadyStruct')
    .then(res => res)
}

export function saveAddress(payload) {
  const path = payload.addressId
    ? 'userAddress/update'
    : 'userAddress/create'

  return http
    .post(path, payload)
    .then(res => res)
}

export function getAddressById(addressId) {
  return http
    .get('userAddress/view', { addressId })
    .then(res => res)
}

export function deleteAddressById(addressId) {
  return http
    .post('userAddress/delete', { addressId })
    .then(res => res)
}

export function getAddressList() {
  return http
    .get('userAddress/list', null, { cacheable: true, maxAge: 10 })
    .then(res => res)
}
